package com.tudouji.project.arealand.controller;

import java.util.List;
import java.util.Map;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.arealand.domain.TArealand;
import com.tudouji.project.arealand.service.ITArealandService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;

/**
 * 地块Controller
 * 
 * @author tudouji
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/tarealand/arealand")
public class TArealandController extends BaseController
{
    @Autowired
    private ITArealandService tArealandService;

    /**
     * 查询地块列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TArealand tArealand)
    {
        startPage();
        List<TArealand> list = tArealandService.selectTArealandList(tArealand);
        return getDataTable(list);
    }

    /**
     * 导出地块列表
     */
    @PreAuthorize("@ss.hasPermi('tarealand:arealand:export')")
    @Log(title = "地块", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TArealand tArealand)
    {
        List<TArealand> list = tArealandService.selectTArealandList(tArealand);
        ExcelUtil<TArealand> util = new ExcelUtil<TArealand>(TArealand.class);
        return util.exportExcel(list, "arealand");
    }

    /**
     * 获取地块详细信息
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(tArealandService.selectTArealandById(guid));
    }

    /**
     * 新增地块
     */
    @Log(title = "地块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TArealand tArealand)
    {
        return toAjax(tArealandService.insertTArealand(tArealand));
    }

    /**
     * 修改地块
     */
    @Log(title = "地块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TArealand tArealand)
    {
        return toAjax(tArealandService.updateTArealand(tArealand));
    }

    /**
     * 删除地块
     */
    @Log(title = "地块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(tArealandService.deleteTArealandByIds(guids));
    }


    /**
     * 新增地块
     */
    @Log(title = "地块", businessType = BusinessType.INSERT)
    @PostMapping("saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody TArealand tArealand, String fileIds)
    {
        return tArealandService.saveOrUpdate(tArealand, fileIds);
    }

    /**
     * 获取地块详细信息
     */
    @GetMapping(value = "/getAreaLands")
    public AjaxResult getAreaLands(String latitude, String longitude)
    {
        return tArealandService.getAreaLands(latitude, longitude);
    }

    /**
     * 获取地块详细信息
     */
    @GetMapping(value = "/getAreaLandsByFarmerId")
    public AjaxResult getAreaLandsByFarmerId(String farmerid)
    {
        return tArealandService.getAreaLandsByFarmerId(farmerid);
    }
}
